package com.ruoyi.web.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.agriculture.domain.Agriculture;
import com.ruoyi.agriculture.service.IAgricultureService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品销售Controller
 * 
 * @author z
 * @date 2025-08-25
 */
@RestController
@RequestMapping("/agriculture/agriculture")
public class AgricultureController extends BaseController
{
    @Autowired
    private IAgricultureService agricultureService;

    /**
     * 查询产品销售列表
     */
    @PreAuthorize("@ss.hasPermi('agriculture:agriculture:list')")
    @GetMapping("/list")
    public TableDataInfo list(Agriculture agriculture)
    {
        startPage();
        List<Agriculture> list = agricultureService.selectAgricultureList(agriculture);
        return getDataTable(list);
    }

    /**
     * 导出产品销售列表
     */
    @PreAuthorize("@ss.hasPermi('agriculture:agriculture:export')")
    @Log(title = "产品销售", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Agriculture agriculture)
    {
        List<Agriculture> list = agricultureService.selectAgricultureList(agriculture);
        ExcelUtil<Agriculture> util = new ExcelUtil<Agriculture>(Agriculture.class);
        util.exportExcel(response, list, "产品销售数据");
    }

    /**
     * 获取产品销售详细信息
     */
    @PreAuthorize("@ss.hasPermi('agriculture:agriculture:query')")
    @GetMapping(value = "/{agricultureId}")
    public AjaxResult getInfo(@PathVariable("agricultureId") Long agricultureId)
    {
        return success(agricultureService.selectAgricultureByAgricultureId(agricultureId));
    }

    /**
     * 新增产品销售
     */
    @PreAuthorize("@ss.hasPermi('agriculture:agriculture:add')")
    @Log(title = "产品销售", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Agriculture agriculture)
    {
        return toAjax(agricultureService.insertAgriculture(agriculture));
    }

    /**
     * 修改产品销售
     */
    @PreAuthorize("@ss.hasPermi('agriculture:agriculture:edit')")
    @Log(title = "产品销售", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Agriculture agriculture)
    {
        return toAjax(agricultureService.updateAgriculture(agriculture));
    }

    /**
     * 删除产品销售
     */
    @PreAuthorize("@ss.hasPermi('agriculture:agriculture:remove')")
    @Log(title = "产品销售", businessType = BusinessType.DELETE)
	@DeleteMapping("/{agricultureIds}")
    public AjaxResult remove(@PathVariable Long[] agricultureIds)
    {
        return toAjax(agricultureService.deleteAgricultureByAgricultureIds(agricultureIds));
    }
}
